UNPKG

7.9 kBHTMLView Raw
1<!DOCTYPE html>
2<html lang="en">
3<head>
4 <meta charset="utf-8">
5 <title>JSDoc: Tutorial: Loki Angular</title>
6
7 <script src="scripts/prettify/prettify.js"> </script>
8 <script src="scripts/prettify/lang-css.js"> </script>
9 <!--[if lt IE 9]>
10 <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
11 <![endif]-->
12 <link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
13 <link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
14</head>
15
16<body>
17
18<div id="main">
19
20 <h1 class="page-title">Tutorial: Loki Angular</h1>
21
22 <section>
23
24<header>
25
26
27 <h2>Loki Angular</h2>
28</header>
29
30<article>
31 <h1>Lokiwork, the LokiJS Angular Service</h1><h2>Overview</h2><p>This service of Lokijs for Angular simplifies things to the most basic level because i found Loki difficult to work with in a mobile environment. all you do is setup json files that specify the layout of your data then add, and update entries to the databases.</p>
32<h3>Demo</h3><p>View the Plunker demo <a href="http://plnkr.co/3H1kgFKWsr341zsWLZvp">here</a>.</p>
33<h3>Install:</h3><p><code>bower install lokijs</code></p>
34<h3>Html:</h3><pre class="prettyprint source"><code>&lt;script src=&quot;bower_components/lokijs/src/lokijs.js&quot;>&lt;/script>
35&lt;script src=&quot;bower_components/lokijs/src/loki-angular.js&quot;>&lt;/script></code></pre><h3>App:</h3><p><code>angular.module('app',['lokijs']);</code></p>
36<h3>Configure database template:</h3><p>I might call this file -&gt; <code>json_locations.js</code> Note: each one has to be called, json1, json2, json3, etc as shown in the following: </p>
37<pre class="prettyprint source"><code>app.constant(
38 'json1',
39 {
40 &quot;db&quot;:&quot;settings&quot;,
41 &quot;collection&quot;: &quot;globals&quot; ,
42 &quot;documents&quot; :
43 [
44 {
45 &quot;name&quot;: &quot;user settings&quot;,
46 &quot;brands&quot; : true,
47 &quot;random&quot; : &quot;some value&quot;
48 }
49 ]
50 }
51 );</code></pre><h3>Controller:</h3><pre class="prettyprint source"><code>app.controller('myCtrl', function($scope, Lokiwork){...});</code></pre><h3>Usage:</h3><p>Lokiwork.setCurrentDoc(dbname, collection, document_identifier);</p>
52<pre class="prettyprint source"><code>Lokiwork.setCurrentDoc('settings', 'globals', {'name': &quot;user settings&quot;});</code></pre><p>Lokiwork.getCurrentDoc();</p>
53<pre class="prettyprint source"><code>Lokiwork.getCurrentDoc();</code></pre><p>Lokiwork.updateCurrentDoc(name, value);</p>
54<pre class="prettyprint source"><code>Lokiwork.updateCurrentDoc(&quot;power&quot;, true);</code></pre><p>Lokiwork.deleteCurrentDoc();</p>
55<pre class="prettyprint source"><code>Lokiwork.deleteCurrentDoc();</code></pre><p>Lokiwork.getDoc(dbName, collName, docName);</p>
56<pre class="prettyprint source"><code>Lokiwork.getDoc(&quot;settings&quot;, &quot;globals&quot;, {name:&quot;user settings&quot;});</code></pre><p>Lokiwork.addDocument(dbName, collName, newDoc);</p>
57<pre class="prettyprint source"><code>Lokiwork.addDocument(&quot;settings&quot;, &quot;globals&quot;, doc_obj); //example below</code></pre><p>Lokiwork.updateDoc(dbname, collName, document_identifier, name, value);</p>
58<pre class="prettyprint source"><code>Lokiwork.updateDoc(&quot;settings&quot;, &quot;globals&quot;, {name:&quot;user settings&quot;}, &quot;brands&quot;, false});</code></pre><p>Lokiwork.deleteDocument(dbName, collName, document_identifier);</p>
59<pre class="prettyprint source"><code>Lokiwork.deleteDocument('settings','globals', {name:'user settings'});</code></pre><p>Lokiwork.getCollection(dbName, collName);</p>
60<pre class="prettyprint source"><code>Lokiwork.getCollection('settings', 'globals');</code></pre><p>Lokwork.addCollection(json_obj);</p>
61<pre class="prettyprint source"><code>Lokiwork.addCollection(item); // example below</code></pre><p>Lokiwork.deleteCollection(dbName, collName);</p>
62<pre class="prettyprint source"><code>Lokiwork.deleteCollection('settings', globals');</code></pre><p>Lokiwork.deleteDatabase(dbName);</p>
63<pre class="prettyprint source"><code>Lokiwork.deleteDatabase(&quot;settings&quot;);</code></pre><h4>Further examples:</h4><pre class="prettyprint source"><code>var collection = {
64 &quot;db&quot;:&quot;settings&quot;,
65 &quot;collection&quot;: &quot;globals&quot; ,
66 &quot;documents&quot; :
67 [
68 {
69 &quot;name&quot;: &quot;user settings&quot;,
70 &quot;brands&quot; : true,
71 &quot;face&quot; : &quot;You now it&quot;
72 }
73 ]
74};
75 Lokiwork.addCollection(collection);</code></pre><p>With addDocument, you can pass a json document in if it's small enough, otherwise assign it to a variable first.</p>
76<pre class="prettyprint source"><code>Lokiwork.addDocument(&quot;settings&quot;, &quot;globals&quot;, {name:&quot;user settings2&quot;, gay: true, brands:false})</code></pre><p>You can also use promises and/or chain them:</p>
77<pre class="prettyprint source"><code>Lokiwork.setCurrentDoc('settings', 'globals', {'name': &quot;user settings&quot;})
78 .then(function(data){
79 Lokiwork.updateCurrentDoc(&quot;address&quot;, &quot;1801 Waters Ridge Drive&quot;);
80 });</code></pre><h3>Remember!</h3><p>A lot of the above commands may not be necessary if you are implementing a static change, just edit the underlying json javascript file, delete the local storage file, and restart the app.</p>
81<h3>Notes:</h3><ul>
82<li>If you delete a database it's recreated the next time the app is restarted and on the first query because it will see the angular json file and recreate it (it won't overwrite existing though). If you want to permanantly remove a database, then you have to also remove the angular json file. This is perfect, because on a mobile device the user may have local storage wiped, no problem, because the next time they boot up the databases will all be recreated.</li>
83<li>Since Lokijs is generating all of the database content it should be 100% compatible with native Lokijs commands not listed here but found on the office website shown below.</li>
84</ul>
85<h3>The official Lokijs page</h3><p><a href="https://github.com/techfort/LokiJS">LokiJS</a></p>
86</article>
87
88</section>
89
90</div>
91
92<nav>
93 <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Collection.html">Collection</a></li><li><a href="DynamicView.html">DynamicView</a></li><li><a href="Loki.html">Loki</a></li><li><a href="LokiEventEmitter.html">LokiEventEmitter</a></li><li><a href="LokiFsAdapter.html">LokiFsAdapter</a></li><li><a href="LokiFsStructuredAdapter.html">LokiFsStructuredAdapter</a></li><li><a href="LokiIndexedAdapter.html">LokiIndexedAdapter</a></li><li><a href="LokiLocalStorageAdapter.html">LokiLocalStorageAdapter</a></li><li><a href="LokiMemoryAdapter.html">LokiMemoryAdapter</a></li><li><a href="LokiPartitioningAdapter.html">LokiPartitioningAdapter</a></li><li><a href="Resultset.html">Resultset</a></li></ul><h3>Tutorials</h3><ul><li><a href="tutorial-Autoupdating Collections.html">Autoupdating Collections</a></li><li><a href="tutorial-Changes API.html">Changes API</a></li><li><a href="tutorial-Collection Transforms.html">Collection Transforms</a></li><li><a href="tutorial-Indexing and Query performance.html">Indexing and Query performance</a></li><li><a href="tutorial-Loki Angular.html">Loki Angular</a></li><li><a href="tutorial-Persistence Adapters.html">Persistence Adapters</a></li><li><a href="tutorial-Query Examples.html">Query Examples</a></li></ul>
94</nav>
95
96<br class="clear">
97
98<footer>
99 Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.0</a> on Sun Dec 18 2016 19:39:52 GMT-0500 (Eastern Standard Time)
100</footer>
101
102<script> prettyPrint(); </script>
103<script src="scripts/linenumber.js"> </script>
104</body>
105</html>
\No newline at end of file